package com.like.hospitalworld;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;
import android.view.View;

import com.like.adapter.GuidePagerAdapter;
import com.like.entity.M;
import com.like.likeutils.storage.SPUtils;
import com.viewpagerindicator.CirclePageIndicator;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

@ContentView(R.layout.activity_guide)
public class GuideActivity extends BaseActivity {

    @ViewInject(R.id.guide_pager)
    ViewPager mGuidePager;
    @ViewInject(R.id.indicator)
    CirclePageIndicator mIndicator;

    private GuidePagerAdapter mPagerAdapter;
    private float mCurrentX = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SPUtils.put(m.mContext, M.FLAG_IS_FIRST_RUM, false);
        mPagerAdapter = new GuidePagerAdapter(getSupportFragmentManager());
        mGuidePager.setAdapter(mPagerAdapter);
        mIndicator.setViewPager(mGuidePager);
        mGuidePager.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (mGuidePager.getCurrentItem() != mPagerAdapter.getCount() - 1)
                    return false;
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        mCurrentX = event.getX();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        break;
                    case MotionEvent.ACTION_UP:
                        if (mCurrentX - event.getX() > 200) {
                            Intent intent = new Intent(m.mContext, LoginActivity.class);
                            startActivity(intent);
                            finish();
                        }
                        break;
                }
                return false;
            }
        });
    }
}
